package com.hadoop.project.gen.maodalitest;

import com.hadoop.project.entity.hbase.HBaseResult;
import com.hadoop.project.entity.po.TabRank;
import com.hadoop.project.entity.po.UserFlavor;
import com.hadoop.project.entity.po.VideoRank;
import com.hadoop.project.entity.hbase.ProcessRes;
import com.hadoop.project.utils.Processor;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 * @author Alexmaodali
 * @usage:测试计算数据
 */
public class SimpleTest {
    @Test
    public void test() throws Exception {
        HBaseResult hbaseResult = TestProcessingData.genHBaseData(10,10,100);
        ProcessRes processRes   = Processor.processHBaseData(hbaseResult);
        System.out.println(processRes);

        String o = ";";

        // String YourPath = "E:\\Home\\ServerFileManage\\gen\\";
        String YourPath = "E:\\Home\\ServerFileManage\\gen\\";

        String tabRankFilePath    = YourPath + "tab-rank.txt";
        String userFlavorFilePath = YourPath + "user-flavor.txt";
        String videoRankFilePath  = YourPath + "video-rank.txt";

        Boolean writeTabRank    = false;
        Boolean writeUserFlavor = false;
        Boolean writeVideoRank  = true;

        // TabRank写入
        if (writeTabRank) {
            for (TabRank tabRank : processRes.getTabRankList()) {
                try (BufferedWriter writer = new BufferedWriter(new FileWriter(tabRankFilePath, true))) {
                    String str = tabRank.getId().toString() + o + tabRank.getTname() + o + tabRank.getCnt().toString();
                    writer.write(str);
                    writer.newLine();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        // UserFlavor写入
        if (writeUserFlavor) {
            for (UserFlavor userFlavor : processRes.getUserFlavorList()) {
                try (BufferedWriter writer = new BufferedWriter(new FileWriter(userFlavorFilePath, true))) {
                    String str = userFlavor.getId() + o + userFlavor.getUid() + o + userFlavor.getTname() + o + userFlavor.getTpercent();
                    writer.write(str);
                    writer.newLine();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        // VideoRank写入
        if (writeVideoRank) {
            for (VideoRank videoRank : processRes.getVideoRankList()) {
                try (BufferedWriter writer = new BufferedWriter(new FileWriter(videoRankFilePath, true))) {
                    String str = videoRank.getId() + o + videoRank.getVid() + o + videoRank.getViews();
                    writer.write(str);
                    writer.newLine();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
